function [a,P] =GoToLocation(P,S,mode,T_X, T_Y)
if(isempty(S) || size(S{1},2)~=2),a='turn 45';
else if(~isempty(S) && size(S{1},2)==2)
        B=S{1};
        
        P_X=P{1}(1);
        P_Y=P{1}(2);
        P_theta=P{1}(3);
        P_pace = P{5};
        
        angle=atan2(T_Y-P_Y,T_X-P_X)/pi*180;    %compute the angle to the ball after 3 time steps in degrees
        
        if(angle<0)
            angle=angle+360;    %correct the angle3
        end
        angle=angle-P_theta;      %the angle between the player and the ball after 3 steps
        if(angle<0)
            angle=angle+360;    %correct the angle3
        end
        
        angle=round(angle/45)*45;   %discretize angle3 into the nearest 45 degree
        
        if(((round(T_X)==P_X && round(T_Y)==P_Y) || ...    %over the ball
            (round(T_X)==T_X+sign(round(cos(P_theta/180*pi))) && round(T_Y)==P_Y+sign(round(sin(P_theta/180*pi)))) || ...    %in one of the three kicking cells
            (round(T_X)==P_X+sign(round(cos((P_theta+45)/180*pi))) && round(T_Y)==P_Y+sign(round(sin((P_theta+45)/180*pi)))) || ...
            (round(T_X)==P_X+sign(round(cos((P_theta-45)/180*pi))) && round(T_Y)==P_Y+sign(round(sin((P_theta-45)/180*pi))))))
        
            a = '';
            %a = 'kick -10 0';
        else 
            if(angle<=45 || angle>=360-45)
                %a='dash 10';
                a = sprintf('dash %d', P_pace);
            else
                r=rand(1);
                if(r>0.7),
                    %a = 'dash 10';
                    a = sprintf('dash %d', P_pace);
                else
                    if(angle<180)
                        a=sprintf('turn %d',angle);
                    else
                        a=sprintf('turn %d',angle-360);
                    end
                end
            end
        end
        
    end
    
end
end